<?php
namespace App\Services;
use Exception,Log;
use Zxing\QrReader;

class Qrcodedecoder
{

    public static function qrcodeDecoder($qrcode_path)
    {
        try {          
            $qrcode = new QrReader($qrcode_path);
            $text = $qrcode->text();
            return $text;
        } catch (Exception $e) {
            return '';
        }
    }

    public static function judgeQrcode($qrcode_path)
    {
        $bool = 'empty';
        try {
            $text = self::qrcodeDecoder($qrcode_path);
            if(strpos($text,'http://weixin.qq.com') === 0){
                $bool = 'official';
            }elseif(strpos($text,'https://u.wechat.com') === 0){
                $bool = 'wechat';
            }elseif(strpos($text,'https://weixin.qq.com') === 0 || strpos($text,'https://c.weixin.com') === 0){
                $bool = 'group';
            }elseif(strpos($text,'https://work.weixin.qq.com') === 0){
                $bool = 'work';
            }else{
                $bool = 'other';
            }
        } catch (Exception $e) {
            $bool = 'empty';
        }
        return $bool;
    }
}
